package com.anhry.www.safety.util.service.impl;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.anhry.www.safety.util.Param;
import com.anhry.www.safety.util.dao.UtilDao;
import com.anhry.www.safety.util.service.UtilService;

@Service
public class UtilServiceImpl implements UtilService{
	@Resource
	private UtilDao utilDao;

	public UtilDao getUtilDao() {
		return utilDao;
	}

	public void setUtilDao(UtilDao utilDao) {
		this.utilDao = utilDao;
	}

	public void delete(Object obj) throws Exception {
		this.utilDao.delete(obj);
		
	}

	public Object getObjectById(Class classes, String id) throws Exception {
		return this.utilDao.getObjectById(classes, id);
	}

	public Object getObjectById(Class classes, int id) throws Exception {
		return this.utilDao.getObjectById(classes, id);
	}

	public void save(Object obj) throws Exception {
		this.utilDao.save(obj);
		
	}

	public void update(Object obj) throws Exception {
		this.utilDao.update(obj);
		
	}

	public Object getObjectById(Class classes, Long id) throws Exception {
		return this.utilDao.getObjectById(classes, id);
	}

	public Object getHqlQuery(String hql) throws Exception {
		return this.utilDao.getHqlQuery(hql);
	}

	public Collection getHqlQuery(String hql, int start, int count) throws Exception {
		return this.utilDao.getHqlQuery(hql, start, count);
	}

	public Object getCollection(String objName, List<Param> params, Map orders, int start, int count) throws Exception {
		return this.utilDao.getCollection(objName, params, orders, start, count);
	}

	public int getHqlQuerySize(String hql) throws Exception {
		return this.utilDao.getHqlQuerySize(hql);
	}

	public void deleteAll(String objName, List<Param> params) throws Exception {
		this.utilDao.deleteAll(objName, params);
	}

	public void updateAll(String objName, Map sets, List<Param> params) throws Exception {
		this.utilDao.updateAll(objName, sets, params);
	}

	public void saveOrUpdate(Object obj) throws Exception {
		this.utilDao.saveOrUpdate(obj);
	}

	public List getFjList(String classes, String id) throws Exception {
		return this.utilDao.getFjList(classes, id);
	}

	public void deleteBySql(String sql) throws Exception {
		this.utilDao.deleteBySql(sql);
	}

	public List getObjectBySql(String sql, int start, int count)throws Exception {
		return this.utilDao.getObjectBySql(sql,start,count);
	}
    public <T> T getObject(Class<T> clazz, String ID) throws Exception {
	    return utilDao.getObject(clazz,ID);
    }
    
	public String getObjectBySql(String sql) throws Exception {
		return this.utilDao.getObjectBySql(sql);
	}

	public List getObjecList(String table, String hql, String order, int start,int count) throws Exception {
		StringBuffer hqls = new StringBuffer();
		if(count == 0){
			hqls.append("select count(*) from "+table+" t ").append(hql);
		}else{
			hqls.append("from "+table+" t ").append(hql).append(order);
		}
		return (List)this.utilDao.getHqlQuery(hqls.toString(), start, count);
	}



}
